//
//  CycleColumnViewController.m
//  礼物go
//
//  Created by dllo on 16/5/20.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CycleColumnViewController.h"
#import "SelectContentModel.h"
#import "SelectTableViewCell.h"
#import "SelectDetailViewController.h"

static NSString *const cycleCCell = @"cycleCCell";
@interface CycleColumnViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)NSMutableArray *dataArray;
@property(nonatomic,strong)UITableView *cycleCTableView;
@end

@implementation CycleColumnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Arial" size:20],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:   UIBarButtonSystemItemReply target:self action:@selector(leftButtonAction)];
    [self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:  UIBarButtonSystemItemAction target:self action:@selector(rightButtonAction)];
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
    self.navigationController.navigationBar.translucent = NO;
    
    self.dataArray = [NSMutableArray array];
    
    self.cycleCTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, self.view.frame.size.height - 66 - 49) style:UITableViewStylePlain];
    [self.view addSubview:self.cycleCTableView];
    self.cycleCTableView.dataSource = self;
    self.cycleCTableView.delegate = self;
    [self.cycleCTableView registerClass:[SelectTableViewCell class] forCellReuseIdentifier:cycleCCell];
    self.cycleCTableView.showsVerticalScrollIndicator = NO;
    
    
    
NSString *urlStr = [NSString stringWithFormat:@"http://api.liwushuo.com/v2/collections/%@/posts?gender=2&generation=4&limit=20&offset=0",self.dataId];
 [LYNetworking ly_GetWithURL:urlStr Parameter:nil success:^(id result) {
     NSDictionary *dataDic = [result objectForKey:@"data"];
     NSString *title = [dataDic objectForKey:@"title"];
      self.navigationItem.title = title;
     NSArray *postsArray = [dataDic objectForKey:@"posts"];
     for (NSDictionary *dic in postsArray) {
         SelectContentModel *selectModel = [[SelectContentModel alloc] init];
         [selectModel setValuesForKeysWithDictionary:dic];
         [self.dataArray addObject:selectModel];
     }
     [self.cycleCTableView reloadData];
     
 } error:^(NSError *error) {
     
     
 }];
        
    
    // Do any additional setup after loading the view.
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SelectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cycleCCell];
    SelectContentModel *select = [self.dataArray objectAtIndex:indexPath.row];
    cell.selectContent = select;
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SelectContentModel *selectModel = [self.dataArray objectAtIndex:indexPath.row];
    SelectDetailViewController *SDVC = [[SelectDetailViewController alloc] init];
    SDVC.dataId = selectModel.myId;
    SDVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:SDVC animated:YES];
    
    
}

-(void)rightButtonAction{

    
}

-(void)leftButtonAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
